//
//  ZHInvoker.swift
//  命令设计模式
//
//  Created by slience on 2019/11/18.
//  Copyright © 2019 shehuiren. All rights reserved.
//

import UIKit

class ZHInvoker: NSObject {
    
    
    var queue : [CommandProtocol2]?
    
    static let shareInstance :ZHInvoker = {
        
         let invoker = ZHInvoker()
        
        invoker.queue = [CommandProtocol2]()
        
        return invoker;
    }()
    
    func rollBack(){
        
        let command  = ZHInvoker.shareInstance.queue?.last
        
        command?.rollBack()
        
        ZHInvoker.shareInstance.queue?.removeLast()
        
    }
    
    func addExcute(command : CommandProtocol2){
        
        ZHInvoker.shareInstance.queue?.append(command)
        command.excute()
    }

}
